﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CreatePhotoInfoFile
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void win1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
        }

        private void win1_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                //
                e.Effects = DragDropEffects.Copy;
                //
                //
                string[] droppedFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                //
                //
                ExifUtils.Exif ex = new ExifUtils.Exif();
                foreach(string f in droppedFiles)
                {
                    if(ExifUtils.Exif.GetExifData(f))
                    {
                        if("" != ExifUtils.Exif.Location && "" != ExifUtils.Exif.DayOfShot)
                        {
                            string info = 
                                ("GPS: " + (ExifUtils.Exif.IsGps ? ExifUtils.Exif.Location : "-")) + Environment.NewLine +
                                ("Day: " + (("" != ExifUtils.Exif.DayOfShot) ? ExifUtils.Exif.DayOfShot : "-"));
                            string ofn = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(f), System.IO.Path.GetFileNameWithoutExtension(f) + ".txt");
                            if (System.IO.File.Exists(ofn))System.IO.File.Delete(ofn);
                            System.IO.File.WriteAllText(ofn, info);
                        }
                        else
                        {
                            MessageBox.Show(System.IO.Path.GetFileName(f) + ": No GPS, no Date!", "Lack of data!");
                        }
                    }
                    else
                    {
                        MessageBox.Show(System.IO.Path.GetFileName(f) + ": No EXIF!", "No EXIF!");
                    }
                }
                //
            }
            //
            e.Effects = DragDropEffects.None;
            //
        }

        private void win1_DragOver(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
        }
    }
}
